package com.shanzhu.hospital.controller;

import com.shanzhu.hospital.common.R;
import com.shanzhu.hospital.entity.po.Surgery;
import com.shanzhu.hospital.entity.vo.SurgeryPageVo;
import com.shanzhu.hospital.service.SurgeryService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("surgery")
@RequiredArgsConstructor
public class SurgeryController {
    private final SurgeryService surgeryService;
    /**
     * 查询手术
     *
     * @return 手术
     */
    @RequestMapping("findSurgeryBySid")
    public R<List<Surgery>> findSurgeryBySid(@RequestParam(value = "sId") int sId) {
        return R.ok(surgeryService.findSurgeryBySid(sId));
    }
    /**
     * 查询手术 - 分页
     *
     * @param pageNum  分页页数
     * @param pageSize 分页大小
     * @param query    查询条件
     * @return 床位数据
     */
    @RequestMapping("findAllSurgery")
    public R<SurgeryPageVo> findAllSurgery(
            @RequestParam(value = "pageNumber") Integer pageNum,
            @RequestParam(value = "size") Integer pageSize,
            @RequestParam(value = "query") String query

    ) {
        SurgeryPageVo allSurgerys = this.surgeryService.findAllSurgerys(pageNum, pageSize, query);
        return R.ok(allSurgerys);
    }
    /**
     *
     *
     * @param sId 手术id
     * @return 手术信息
     */
    @RequestMapping("findSurgery")
    public R<Surgery> findSurgery(Integer sId) {
        return R.ok(surgeryService.findSurgery(sId));
    }

    /**
     * 添加手术
     *
     * @param surgery 手术信息
     * @return 结果
     */
    @RequestMapping("addSurgery")
    public R<Boolean> addSurgery(Surgery surgery) {
        if (BooleanUtils.isTrue(surgeryService.addSurgery(surgery))) {
            return R.ok("增加床位成功");
        }

        return R.error("增加床位失败！床号或已被占用");
    }
    /**
     * 更新手术
     *
     * @param  surgery 手术信息
     * @return 结果
     */
    @RequestMapping("updatesurgery")
    public R<Boolean> updatesurgery(Surgery surgery) {
        if (BooleanUtils.isTrue(surgeryService.updatesurgery(surgery))) {
            return R.ok("修改手术成功");
        }

        return R.error("修改手术失败");
    }
    /**
     * 删除床位
     *
     * @param sId 床位id
     * @return 结果
     */
    @RequestMapping("deleteSurgery")
    public R<Boolean> deleteSurgery(@RequestParam(value = "sId") int sId) {
        if (BooleanUtils.isTrue(surgeryService.deleteSurgery(sId))) {
            return R.ok("删除手术成功");
        }

        return R.error("删除手术失败");
    }
}
